import React from 'react';
import { Input,Select} from 'antd';
const { Option} =Select
class AccountChange extends React.Component {
  constructor() {
    super()
    this.state = {
      currentmoney:0
    }
  }
  getInput = (iszeng,chdata) => {
    return (e) => {
      let totalmoney
      if (iszeng === 'zengjia') {
        totalmoney =parseInt(e.target.value)  + this.state.currentmoney
      } else {
        totalmoney = this.state.currentmoney-parseInt(e.target.value) 
      }
      this.setState({
        currentmoney:totalmoney
      })
      this.props.getall.account[ chdata ] = totalmoney
      this.props.getall.changeAccount(this.props.getall.account); 
    }
  }
  render() {
    let {handleChange,iszeng,acname,chdata}=this.props
  return (
    <div>
      <span>{acname }</span>
      <Select defaultValue="增加" style={{ width: 80 }} onChange={handleChange}>
        <Option value="zengjia">增加</Option>
        <Option value="jianshao">减少</Option>
      </Select>
      <Input className='juzhonginput' style={{ width: '20%' }} placeholder='输入您要增加或删除的金额，按回车建确定' onPressEnter={this.getInput(iszeng,chdata)} />
      <span>当前值：¥</span>
      <span>{ this.state.currentmoney}</span>
    </div>
  );
  }
}
export default AccountChange;